﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace MotelServices
{
    public class PhuongBUS
    {
         public static string _connString = string.Empty;

        #region Static Contructor
         static PhuongBUS()
        {
            _connString = ConfigurationManager.ConnectionStrings["MotelConnectionString"].ConnectionString.ToString();
        } 
        #endregion

        #region Function to get all address
        public static List<PhuongDTO> LayPhuong(int maquan)
        {
            List<PhuongDTO> ldc = new List<PhuongDTO>();
            DataMotelDataContext dtdc = new DataMotelDataContext(_connString);
            try
            {
                var DiaChiObj = (from dc in dtdc.Phuongs
                                 where dc.MaQuan.Equals(maquan)
                                 select dc);
                foreach (var item in DiaChiObj)
                {
                    PhuongDTO dc = new PhuongDTO();
                    dc.MaPhuong = item.MaPhuong;
                    dc.TenPhuong = item.TenPhuong;
                    ldc.Add(dc);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                dtdc.Dispose();
            }
            return ldc;
        } 
        #endregion
    }
}